package 设计原则;

import java.text.MessageFormat;

/**
 * TODO
 *
 * @author scylla
 * @version V1.0
 * @project echo-java-base
 * @title
 * @package 临时示例包
 * @since 2023/2/24 5:48 下午
 */
public class CARP {

    interface DBConnection {
        String getConnection();
    }

    public class OdbcConnection implements DBConnection {
        public OdbcConnection() {}

        @Override
        public String getConnection() {
            return "ODBC连接";
        }
    }

    public class JdbcConnection implements DBConnection {
        public JdbcConnection() {}

        @Override
        public String getConnection() {
            return "JDBC连接";
        }
    }

    public class SqlClient {
        DBConnection dbConnection;

        public void setDbConnection(DBConnection dbConnection) {
            this.dbConnection = dbConnection;
        }

        public void saveConnect(Object params) {
            System.out.println(MessageFormat.format("以获取连接类型：{0},保存成功!", this.dbConnection.getConnection()));
        }
    }

    public void test(String[] args) {
        SqlClient sqlClient1 = new SqlClient();
        sqlClient1.setDbConnection(new JdbcConnection());
        sqlClient1.saveConnect(new Object());

        SqlClient sqlClient2 = new SqlClient();
        sqlClient1.setDbConnection(new OdbcConnection());
        sqlClient2.saveConnect(new Object());
    }

}
